<?php
/**
 * Created by PhpStorm.
 * User: chen
 * Date: 18-5-26
 * Time: 下午3:03
 */

namespace App\ServiceHandler\Common;


use App\Model\Common\Module;

class ModuleService
{
    /**
     * 修改和添加方法，修改时传入id
     * @param $array
     * @param null $id
     * @return bool|null
     */
    public static function post($array, $id = null){
        $module = null;
        if(empty($id)){
            $module = new Module();
        }else{
            $module = Module::find($id);
        }
        $module->name = $array['name'];
        if($module->isValid()){
            return $module->save();
        }
        return $module->errors;
    }

    public static function lists(){
        return Module::paginate(Module::per_page());
    }
}